﻿@page "/user_auth/resource"
<div>
    <PageContainer Title="">
        <Breadcrumb>
            <Breadcrumb>
                <BreadcrumbItem>用户权限</BreadcrumbItem>
                <BreadcrumbItem>资源管理</BreadcrumbItem>
            </Breadcrumb>
        </Breadcrumb>
        <ChildContent>
            <div>
                <Row>
                    <AntDesign.Col Span="8">
                        <Row>
                            <AntDesign.Col Span="18">
                                <Space>
                                    <ResourceAuthorize ResourceKey="user_auth_resource_switch">
                                        <SpaceItem>
                                            <Tooltip Placement="PlacementType.TopLeft" Title="@(isExpanded?"收起":"展开")">
                                                <Button Type="@ButtonType.Primary" Icon="@(isExpanded?"up":"down")" Size="@ButtonSize.Small" OnClick="OnExpandClick" />
                                            </Tooltip>
                                        </SpaceItem>
                                    </ResourceAuthorize>
                                    <ResourceAuthorize ResourceKey="user_auth_resource_refresh">
                                        <SpaceItem>
                                            <Tooltip Placement="PlacementType.TopLeft" Title="@("刷新")">
                                                <Button Type="@ButtonType.Primary" Icon="reload" Size="@ButtonSize.Small" OnClick="OnReloadClick" />
                                            </Tooltip>
                                        </SpaceItem>
                                    </ResourceAuthorize>
                                    <ResourceAuthorize ResourceKey="user_auth_resource_add">
                                        <SpaceItem>
                                            <Tooltip Placement="PlacementType.TopLeft" Title="@("添加子节点")">
                                                <Button Type="@ButtonType.Primary" Icon="plus-circle" Size="@ButtonSize.Small" OnClick="_=>OnAddChildNodeClick(null)" />
                                            </Tooltip>
                                        </SpaceItem>
                                    </ResourceAuthorize>
                                    <ResourceAuthorize ResourceKey="user_auth_resource_edit">
                                        <SpaceItem>
                                            <Tooltip Placement="PlacementType.TopLeft" Title="@("编辑选中节点")">
                                                <Button Type="@ButtonType.Primary" Icon="edit" Size="@ButtonSize.Small" OnClick="_=>OnEditSelectedNodeClick(null)" />
                                            </Tooltip>
                                        </SpaceItem>
                                    </ResourceAuthorize>
                                    <ResourceAuthorize ResourceKey="user_auth_resource_delete">
                                        <SpaceItem>
                                            <Tooltip Placement="PlacementType.TopLeft" Title="@("删除选中及所有子节点")">
                                                <Button Type="@ButtonType.Primary" Icon="delete" Danger Size="@ButtonSize.Small" OnClick="_=>OnDeleteSelectedNodeClick(null)" />
                                            </Tooltip>
                                        </SpaceItem>
                                    </ResourceAuthorize>
                                </Space>
                            </AntDesign.Col>
                        </Row>
                        <Row>
                            <AntDesign.Col Span="24" Style="margin-top:10px">
                                <Spin Spinning="@treeIsLoading">
                                    <Tree @ref="tree"
                                          ShowLine
                                          TitleExpression="x=> ((ResourceDto)x.DataItem).GetFullName()"
                                          ChildrenExpression="x=>((ResourceDto)x.DataItem).Children"
                                          IconExpression="x=>((ResourceDto)x.DataItem).Icon"
                                          IsLeafExpression="x=>false"
                                          OnClick="OnNodeClick"
                                          OnExpandChanged="e=> { isExpanded = e.Node.IsExpanded; }"
                                          Style="min-height:466px;">
                                        <TitleTemplate Context="node">
                                            <div class="tree-node">
                                                <div class="title">
                                                    <Space>
                                                        @if (!string.IsNullOrEmpty(node.Icon))
                                                        {
                                                            <SpaceItem><Icon Type="@node.Icon" /></SpaceItem>
                                                        }
                                                        <SpaceItem><span>@node.Title</span></SpaceItem>
                                                    </Space>
                                                </div>
                                                <div class="action">
                                                    <ResourceAuthorize ResourceKey="user_auth_resource_add">
                                                        <Button Type="@ButtonType.Link" Size="@ButtonSize.Small" OnClick="x=>OnAddChildNodeClick(node)">
                                                            <Icon Type="plus"></Icon>
                                                        </Button>
                                                    </ResourceAuthorize>
                                                    <ResourceAuthorize ResourceKey="user_auth_resource_edit">
                                                        <Button Type="@ButtonType.Link" Size="@ButtonSize.Small" OnClick="x=>OnEditSelectedNodeClick(node)">
                                                            <Icon Type="edit"></Icon>
                                                        </Button>
                                                    </ResourceAuthorize>
                                                    <ResourceAuthorize ResourceKey="user_auth_resource_delete">
                                                        <Button Type="@ButtonType.Link" Size="@ButtonSize.Small" Danger OnClick="x=>OnDeleteSelectedNodeClick(node)">
                                                            <Icon Type="delete"></Icon>
                                                        </Button>
                                                    </ResourceAuthorize>
                                                </div>
                                            </div>
                                        </TitleTemplate>
                                    </Tree>
                                </Spin>
                            </AntDesign.Col>
                        </Row>
                    </AntDesign.Col>
                    <AntDesign.Col Span="12" Offset="2">
                        <Spin Spinning="descriptionsIsLoading">
                            <Descriptions Title="资源信息" Bordered Layout="@DescriptionsLayout.Vertical" Style="margin-top:10px">
                                <DescriptionsItem Title="标示">@selectedModel.Id</DescriptionsItem>
                                <DescriptionsItem Title="名称">@selectedModel.Name</DescriptionsItem>
                                <DescriptionsItem Title="键值">@selectedModel.Key</DescriptionsItem>
                                <DescriptionsItem Title="类型">
                                    @(EnumExtension.GetEnumDescription(selectedModel.Type))
                                </DescriptionsItem>
                                <DescriptionsItem Title="排序">
                                    @selectedModel.Order
                                </DescriptionsItem>
                                <DescriptionsItem Title="图标">
                                    @if (!string.IsNullOrEmpty(selectedModel.Icon))
                                    {
                                        <Icon Type="@selectedModel.Icon"></Icon>
                                    }
                                    <sppn>@selectedModel.Icon</sppn>
                                </DescriptionsItem>
                                <DescriptionsItem Title="锁定">
                                    <TagYesNo Yes="selectedModel.IsLocked"></TagYesNo>
                                </DescriptionsItem>
                                <DescriptionsItem Title="审计">
                                    <TagYesNo Yes="selectedModel.EnableAudit"></TagYesNo>
                                </DescriptionsItem>
                                <DescriptionsItem Title="创建时间">
                                    @selectedModel.CreatedTime.ToString("yyyy-MM-dd HH:mm:ss")
                                </DescriptionsItem>

                                <DescriptionsItem Title="地址" Span="1">
                                    <Space>
                                        @if (selectedModel.Type.Equals(ResourceType.Api) && selectedModel.Method.HasValue)
                                        {

                                            <SpaceItem>@(EnumExtension.GetEnumDescription(selectedModel.Method))</SpaceItem>
                                        }
                                        <SpaceItem>@selectedModel.Path</SpaceItem>
                                    </Space>
                                </DescriptionsItem>
                                <DescriptionsItem Title="备注" Span="2">
                                    @selectedModel.Remark
                                </DescriptionsItem>
                            </Descriptions>
                        </Spin>
                    </AntDesign.Col>
                </Row>
            </div>
        </ChildContent>
    </PageContainer>
</div>